﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class UtilsBtn : MonoBehaviour
{
    public Sprite on, off;
    public bool select;
    public bool selectOnStart;
    [System.NonSerialized]
    public Button btn;
    public UtilsBtn[] btns;

    private void Start()
    {
        btn = GetComponent<Button>();
        if (selectOnStart) select = true;
        else select = false;
        UpdateImage();
    }

    public void OnClick()
    {
        if (!select) select = true;
        UpdateImage();
        foreach (UtilsBtn bt in btns)
        {
            bt.select = false;
            bt.UpdateImage();
        }
    }

    public void UpdateImage()
    {
        if (select)
            ((Image)btn.targetGraphic).sprite = on;
        else
            ((Image)btn.targetGraphic).sprite = off;
    }
}
